<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>添加会员</title>

    <!-- Bootstrap -->
   	<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
   	<link href="../asset/css/bootstrap-datetimepicker.min.css">
   	<link href="../asset/css/bootstrap-fileinput.css" rel="stylesheet">
  	<link href="./../css/comm.css" rel="stylesheet">
    <link href="./../css/addMembers.css" rel="stylesheet">
		<style type="text/css">
		/*.addPhoto{
			background-color: #acb7bf;
		}*/
		body{
			background-color: #fff;
		}
		.nav-justified{
			border: none;
		}
		.control-label{
			white-space: nowrap;
		}
		.form-horizontal,.memberFormRow{
			height: 80%;
		}
		.addPhoto{
			height: 100%;
		}
		.colorfe2{color: #fe2222;margin: 0.5rem;}
		.time{display: block;
		    width: 100%;
		    height: 45px;
		    padding: 6px 12px;
		    font-size: 14px;
		    line-height: 1.42857143;
		    color: #555;
		    background-color: #fff;
		    background-image: none;
		    border: 1px solid #ccc;
		    border-radius: 4px;
		    -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
		    box-shadow: inset 0 1px 1px rgba(0,0,0,.075);
		    -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
		    -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
		    transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
		}
	</style>
    <!-- HTML5 shim 和 Respond.js 是为了让 IE8 支持 HTML5 元素和媒体查询（media queries）功能 -->
    <!-- 警告：通过 file:// 协议（就是直接将 html 页面拖拽到浏览器中）访问页面时 Respond.js 不起作用 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <!-- begin header -->
    <div id="warning" class="alert alert-warning none">
				<a href="#" class="close" data-dismiss="alert">&times;</a>
				<strong>警告！</strong>请将带<span class="colorfe2">*</span>的内容填写完善!
		</div>
    <header>
        <nav class="navbar navbar-default" style="width: 96%;margin: 0 auto;">
          <ul class="nav nav-tabs nav-justified" style="width: 100%;margin: 0 auto">
            <li>
              <p class="glyphicon glyphicon-menu-left"></p>
            </li>
            <li><p>添加会员</p></li>
          </ul>
        </nav>
    </header>
    <!-- end header -->
    <!-- begin content -->
      <div class="content">
			  <form class="form-horizontal" role="form">
					<div class="container">
						<div class="row memberFormRow" style="margin: 0">
							<div class="col-md-4 addPhoto textcenter">
								<div class="add-img">
									<img style="width: 200px;height: 200px;" src="../img/addFile.jpg" id="headerImg">
									<input type='file' id='file' name='file' accept='image/*'  onchange="preview(this)"/>
								</div>
								<div class="col-md-8 col-md-offset-2 form-btns">
										<button class="btn btn-default">取消</button>
										<button class="btn btn-success" id="subBtn">保存</button>
								</div>
							</div>
							<div class="col-md-8">
								<fieldset>
									<div class="form-group">
											<label for="inputName" class="col-sm-2 control-label"><span class="colorfe2">*</span>姓名</label>
											<div class="col-sm-4">
												<input type="text" class="form-control" id="inputName" placeholder="请输入姓名">
											</div>
											<label class="col-sm-2 control-label"><span class="colorfe2">*</span>性别</label>
											<div class="col-sm-4">
												<select class="form-control sex">
												<option value="0">男</option>
												<option value="1">女</option> 
												</select>
											</div>
									</div>
									<div class="form-group">
											<label class="col-sm-2 control-label"><span class="colorfe2">*</span>电话</label>
											<div class="col-sm-4">
												<input type="text" class="form-control" id="phone" placeholder="请输入电话号码">
											</div>
											<label class="col-sm-2 control-label">身份证</label>
											<div class="col-sm-4">
												<input type="text" class="form-control" id="inputID" placeholder="请输入身份证号码">
											</div>
									</div>
								</fieldset>
								<fieldset>
                  <div class="form-group">
                  	<label for="inputAddr" class="col-sm-2 control-label">地址</label>
                  	<div class="col-sm-10">
                  		<input type="text" class="form-control" id="inputAddr" placeholder="请输入地址">
                  	</div>
                  </div>
                </fieldset>
								<fieldset>
									<div class="form-group">
										<label for="inputOther" class="col-sm-2 control-label">备注</label>
										<div class="col-sm-10">
											<input type="text" class="form-control" id="inputOther" placeholder="请输入备注">
										</div>
									</div>
								</fieldset>
						</div>
					</div>
			   </form>
         <div class="row " style="margin: 0">
           <div class="col-xs-6 col-md-3 col-md-offset-9 form-btns">
             <p class="quxiao">取消</p>
             <p class="successful">保存</p>
				<!-- <button class="btn btn-default">取消</button>
               <button class="btn btn-success successful">保存</button>-->
           </div>
        </div>
      </div>
      <!-- end content -->
		
		<div class="modal fade" id="addsuccess" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		    <div class="modal-dialog">
		        <div class="modal-content">
		            <div class="modal-body" style="text-align: center;"></div>
		        </div><!-- /.modal-content -->
		    </div><!-- /.modal -->
		</div>
    <script src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../asset/js/bootstrap.min.js" ></script>
   	<script type="text/javascript" src="../asset/js/bootstrap-fileinput.js" ></script>
    <script type="text/javascript" src="../asset/js/bootstrap-datetimepicker.min.js"></script>
   	<script type="text/javascript" src="../asset/js/bootstrap-datetimepicker.zh-CN.js"></script>
   	<script type="text/javascript" src="../js/comm.js"></script>
    <script type="text/javascript">
    	//图片预览
    	var attachmentUrl;
    	function preview(obj) {
					var url= window.URL.createObjectURL(obj.files[0]);
					$("#headerImg").attr("src",url);
			    imgUpload(obj.files[0]);
			}
    	/*上传图片*/
			function imgUpload(file){
			    var formData=new FormData();
			    formData.append("imageFile",file);
			  	$.ajax({
		        url: defaultUrl+"/web/uploadHeader",
		        type : "post",
		        processData : false,
		        contentType : false,
		        data:formData,
		        success : function(data) {
		           attachmentUrl = data.obj.imagePath;
							}
		    	});
			}
			
			
    	$(function () {
	    	$(".time").datetimepicker({
					language: 'zh-CN',//显示中文
					format: 'yyyy-mm-dd',//显示格式
					todayHighlight: 1,//今天高亮
					minView: "month",//设置只显示到月份
					startView:2,
					forceParse: 0,
					showMeridian: 1,
					autoclose: 1//选择后自动关闭
					});
					/*提交按钮*/
	    		$('.successful').on('click',function(){
	    			var name = $('#inputName').val().trim();
	    			var sex = $('.sex').val();
	    			var phone = $('#phone').val().trim();
	    			if(phone != ""){
	    				var regs = /^[1][3,4,5,7,8][0-9]{9}$/;
	    				if(!regs.test(phone)){
	    					$('#addsuccess .modal-body').html("手机号码填写错误");
	    					$('#addsuccess').modal('show');
	    					setTimeout(function(){
	        				$('#addsuccess').modal('hide');
	        				},2000)
	    					return;
		    			}
	    			}
	    			var birthday = $('#birthday').val();
	    			var idcard = $('#inputID').val().trim();
	    			if(idcard != ""){
	    				var reg = /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/;
	    				if(!reg.test(idcard)){
	    					$('#addsuccess .modal-body').html("身份证填写错误");
	    					$('#addsuccess').modal('show');
	    					setTimeout(function(){
	        				$('#addsuccess').modal('hide');
	        				},2000)
	    					return;
		    			}
	    			}
	    			var induction = $('#induction').val();
	    			var address = $('#inputAddr').val().trim();
	    			var note = $('#inputOther').val();
	    			if(name == "" || phone == ""){
	    					$('#warning').removeClass('none');
	    					setTimeout(function(){
	    						$('#warning').addClass('none');
	    					},3000)
	    			}else{
		    				$.ajax({
	                url: defaultUrl+'/storeAssociator/insertMember',
	                data: {
	                	attachmentUrl:attachmentUrl,
	                	associatorName:name,
	                	sex:sex,
	                	phone:phone,
	                	birth:birthday,
	                	personId:idcard,
	                	createDate:induction,
	                	address:address,
	                	remarks:note
	                },
	                success: function (data){
	                    console.log(data);
	                    if(data.res == 1){
	                    		$('#addsuccess .modal-body').html("添加成功");
	                    		$('#addsuccess').modal('show');
	                    		setTimeout(function(){
	                    				$('#addsuccess').modal('hide');
	                    				window.location.href="members.html";
	                    		},2000)
	                    }else{
	                    		$('#addsuccess .modal-body').html(data.resMsg);
	                        $('#addsuccess').modal('show');
	                        setTimeout(function(){
	                    				$('#addsuccess').modal('hide');
	                    		},2000)
	                    }
	                },
	                error: function (data) {
	                    console.log("错误");
	                }
	            });
	    			}

	    		})
	    	
	    })
	</script>
   
  </body>
</html>